<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Discussion Board</title>
<meta name="keywords" content="free css website template, gift red, christmas, 3-column layout, CSS, HTML" />
<meta name="description" content="Gift Red is free website template by templatemo.com" />
<link href="templatemo_style.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
<script type="text/javascript" src="//code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" src="//code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js"></script>

<script type='text/javascript' src='js/logging.js'></script>
<script type="text/javascript">
	$(function() {
		$("#register").click(function(){
			location.href="registerView.do";
		});
		
		
		$("#login").click(function(){
			if($("#id").val().length==0){
				alert("아이디를 입력하세요!");
				return;
			}else if($("#password").val().length==0){
				alert("비밀번호를 입력하세요!");
				return;
			}
			$("#loginForm").submit();
		}); 
		
		$("#logoutBtn").click(function(){
			location.href="logout.do";
		});
		
		$("#myPage").click(function(){
			location.href="myPage.do?id=${sessionScope.mvo.id}";
		});
		
		///////////////////////////////////////////////////
		
		<%-- 검색 부분 --%>
		$("#findDisBoard").change(function() {
			$("#findDis").val("");
			if($("#findDisBoard").val()=="contents"){
				$("#findBtn").click(function(){
					//alert("dddd");
					location.href="${initParam.root}/board_findDisContent.do?disContent="+$("#findDis").val();
				});
			} else if($("#findDisBoard").val()=="date") {
				$("#findDis").datepicker({
					dateFormat:"yy-mm-dd",
					dayNamesMin:['일','월','화','수','목','금','토'],
					monthNames:['1월','2월','3월','4월','5월','6월',
					            '7월','8월','9월','10월','11월','12월'],
					constrainInput:true
				});
				
				$("#findBtn").click(function(){
					//alert($("#datepicker").val());
					$.ajax({
						type:"get",
						url:"board_disDatePick.do",
						data:"&no="+$("#findDis").val(),
						dataType:"json",
						success:function(jsonData){
							//alert(jsonData.dvo.id);
							$("#selectResultBoard").html("<table rules=all>"+
								"<tr align=center><td width=100>"+jsonData.dvo.disNo+
								"</td><td>"+jsonData.dvo.disContent+"</td></tr></table>");
							var result="<table rules=all>";
							$.each(jsonData.list,function(index,list) {
								result+="<tr><td width=100>"+list.memberVO.id+"</td>";
								result+="<td>"+list.disReContent+"</td></tr>";
							});
							result+="</table>";
							$("#selectResultReply").html(result);
						}//success
					});//ajax
				});//click
			}//if
		});//change
		
		<%-- 관리자 모드 버튼 --%>
		$("#disAdminBtn").click(function(){
			location.href="${initParam.root}/board_goDisAdmin.do";
		});
		
		<%-- 댓글쓰기 버튼 --%>
		$("#insertReplyBtn").click(function() {
			//alert($("#disReId").val()+" "+$("#disNo").val()+" "+$("#disReContent").val());
			location.href="${initParam.root}/board_insertDisReply.do?memberVO.id="+$("#disReId").val()+"&disReRef="+$("#disNo").val()+"&disReContent="+$("#disReContent").val();
		});
		
		<%-- 댓글 수정 다이얼로그 --%>
		$(":input[name=updateBtn]").click(function() {
			//alert($(":input[name=test]").val());
			//alert($(this).next().val());
			//alert($(this).next().next().val());
			var no = $(this).next().val();
			$("#editReplyDialog").html("<input type=text id=updateReplyContent value="+$(this).next().next().val()+">").dialog({
				resizable:false,
				height:200,
				modal:true,
				buttons: {
					'수정':function() {
						//alert(no);
						//alert($("#updateReplyContent").val());
						location.href="${initParam.root}/board_updateDisReply.do?disReNo="+no+"&disReRef="+$("#disNo").val()+"&disReContent="+$("#updateReplyContent").val();
					},
					'취소':function() {
						$(this).dialog('close');
					}//function
				}//button
			});//dialog
		});//click
		
		<%-- 댓글 삭제 --%>
		$(":input[name=deleteBtn]").click(function() {
			//alert($(this).next().val());
			if(confirm("삭제 하시겠습니까?")) {
				location.href="${initParam.root}/board_deleteDisReply.do?disReNo="+$(this).next().val()+"&disNo="+$("#disNo").val()+"&id=${sessionScope.mvo.id}";
			} else {
				return false;
			}
		});
	});
</script>
</head>
<body>

<div id="templatemo_wrapper">
	
    <!-- <div id="templatemo_header"> -->
    	<div id="site_title"><h1></h1></div>
    	
        <div id="templatemo_menu">
         
            <ul>
              <li><a href="home.do" class="current home">Home</a></li>
              <li><a href="myPage.do">MyPage</a></li>
              <li><a href="ttboard.do">Tech & Tip</a></li>
              <li><a href="news.do">News</a></li>
              <li><a href="qnA.do">QnA</a></li>
              <li ><a href="discussion.do">Discussion</a></li>
              <li ><a href="download.do">Download</a></li>
            </ul>
        </div> <!-- end of templatemo_menu -->   
        
    <!-- </div> end of header -->
    <br><br>
    <div id="templatemo_left_sidebar">
    	<div class="sb_box">
          <div class="content_title"><span></span>Java Box!</div>
				<c:choose>
				<c:when test="${sessionScope.mvo==null }">
				<form action="login.do" method="post" id="loginForm">
				 <input type="text" id="id" name="id" placeholder="ID"><br>
				 <input type="password" id="password" name="password" placeholder="PassWord"><br>
				<input type="button" id="register" value="회원가입">
				<input type="button" id="login" value="로그인"><br><br>
				</form>
				</c:when>
				<c:otherwise>
				ID : ${sessionScope.mvo.id}<br>
				Name : ${sessionScope.mvo.name}<br>
				Point : ${sessionScope.mvo.point}<br>
				Grade : ${sessionScope.mvo.grade}<br>
				<input type="button" value="로그아웃" id="logoutBtn">
				<input type="button" value="마이페이지" id="myPage">
				</c:otherwise>
				</c:choose>
            <ul class="tmo_list">
                <li><a href="#">Praesent pretium ligula</a></li>
                <li><a href="#">Fusce at massa mollis</a></li>
            </ul>
		</div>        
        <a href="#" class="sb_ads"><img src="images/templatemo_ad_1.jpg" alt="image 1" /></a>
        <a href="#" class="sb_ads"><img src="images/templatemo_ad_2.jpg" alt="image 2" /></a>
    
    </div> <!-- end of left sidebar -->
<!-- start of view page -->
     
 <center>
<h2>토론 게시판</h2>

	<!-- 토론 게시판 글 테이블 -->
	<div id="selectResultBoard">
		<table rules="all">
			<tr align="center">
				<td width="100">${requestScope.map.dvo.disNo }</td>
				<td>${requestScope.map.dvo.disContent }</td>
			</tr>
		</table>
	</div>
	<br><br>
	
	<!-- 현재 보이는 게시글 번호 -->
	<input type="hidden" value="${requestScope.map.dvo.disNo }" id="disNo">
    
	<!-- 토론 게시판 댓글 테이블 -->
	<div id="selectResultReply">
		<table rules="all" >
			<c:forEach items="${requestScope.map.list }" var="list">
			<tr>
				<td width="100">${list.memberVO.id}</td>
		<c:choose>
			<c:when test="${sessionScope.mvo.id == list.memberVO.id}">
				<td>${list.disReContent}</td>
				<td width="50">
					<input type="button" value="수정" name="updateBtn">
					<input type="hidden" name="disReNo" value="${list.disReNo}">
					<input type="hidden" name="disReContent" value="${list.disReContent}">
				</td>
				<td width="50">
					<input type="button" value="삭제" name="deleteBtn">
					<input type="hidden" name="disReNo" value="${list.disReNo}">
				</td>
			</c:when>
			<c:otherwise>
				<td colspan="3">${list.disReContent}</td>
			</c:otherwise>
		</c:choose>
			</tr>
			</c:forEach>
			
			<!-- 댓글쓰는 textarea -->
			<c:if test="${sessionScope.mvo != null}">
			<tr>
				<td width="100"><input type="text" id="disReId" value="${sessionScope.mvo.id}" readonly="readonly" size="10"></td>
				<td colspan="2"><textarea id="disReContent" rows="1" cols="60" style="resize:none"></textarea></td>
				<td><input type="button" value="Reply" id="insertReplyBtn"></td>
			</tr>
			</c:if>
		</table>
	</div>
	<br><br>
	
	<!-- 토론 게시판 검색 부분-->
	<select id="findDisBoard">
		<option value="">-------------</option>
		<option value="contents">Contents</option>
		<option value="date">Date</option>
	</select>
	<input type="text" id="findDis">
	<input type="button" id="findBtn" value="검색">
	<c:if test="${sessionScope.mvo.id=='root' }">
		<input type="button" id="disAdminBtn" value="글 목록 관리">
	</c:if>
	<br>
	
	<!-- 다이얼로그 안에 들어갈 div -->
	<div id="editReplyDialog" title="코멘트 수정"></div>
</center>
 
<!-- end of view page -->
<div id="templatemo_footer_wrapper">
    <div id="templatemo_footer">
        Copyright © 2072 <a href="#">Your Company Name</a> | <a rel="nofollow" href="http://www.templatemo.com/preview/templatemo_362_gift_red">Gift Red</a> by <a href="http://www.templatemo.com" rel="nofollow" target="_parent" title="free css templates">templatemo</a>
        <div class="cleaner"></div>
    </div>
</div>
</div>


</body>
</html>